<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
          "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8">
<title>QUnit for ASN1 Encoder Class 'asn1tsp.js'</title>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="qunit.js"></script>
<link rel="stylesheet" href="qunit.css" type="text/css" media="screen" />

<script src="../ext/cj/cryptojs-312-core-fix.js"></script>
<script src="../ext/cj/x64-core.js"></script>
<script src="../ext/cj/cipher-core_min.js"></script>
<script src="../ext/cj/aes_min.js"></script>
<script src="../ext/cj/tripledes_min.js"></script>
<script src="../ext/cj/enc-base64_min.js"></script>
<script src="../ext/cj/md5_min.js"></script>
<script src="../ext/cj/sha1_min.js"></script>
<script src="../ext/cj/sha256_min.js"></script>
<script src="../ext/cj/sha224_min.js"></script>
<script src="../ext/cj/sha512_min.js"></script>
<script src="../ext/cj/sha384_min.js"></script>
<script src="../ext/cj/ripemd160_min.js"></script>
<script src="../ext/cj/hmac_min.js"></script>
<script src="../ext/cj/pbkdf2_min.js"></script>

<script src="../ext/jsbn.js"></script>
<script src="../ext/jsbn2.js"></script>
<script src="../ext/prng4.js"></script>
<script src="../ext/rng.js"></script>
<script src="../ext/rsa.js"></script>
<script src="../ext/rsa2.js"></script>
<script src="../ext/base64.js"></script>
<script src="../src/base64x-1.1.js"></script>
<script src="../src/asn1hex-1.1.js"></script>
<script src="../src/rsapem-1.1.js"></script>
<script src="../src/rsasign-1.2.js"></script>
<script src="../src/crypto-1.1.js"></script>
<script src="../src/keyutil-1.0.js"></script>
<script src="../src/asn1-1.0.js"></script>
<script src="../src/asn1x509-1.0.js"></script>
<script src="../src/asn1cms-1.0.js"></script>
<script src="../src/asn1tsp-1.0.js"></script>
<script src="../src/x509-1.1.js"></script>

<script type="text/javascript">
<!--
$(document).ready(function(){

// _test/z4.* RSA 2048bit
var sZ4_PRVP8PPEM = 
"-----BEGIN PRIVATE KEY-----\n" + 
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otHd55SYO0dLz2oXengw/tZ+q3ZmOPeVmMuOMIYO/Cv1w\n" + 
"k2U0OK4pug4OBSJPhl09Zs6IwB8NwPOU7EDTgMOcQUYB/6QNCI1J7Zm2oLtuchzz\n" + 
"4pIb+o4ZAhVprLhRyvqi8OTKQ7kfGfs5Tuwmn1M/0fQkfzMxADpjOKNgf0uy6lN6\n" + 
"utjdTrPKKFUQNdc6/Ty8EeTnQEwUlsT2LAXCfEKxTn5RlRljDztS7Sfgs8VL0FPy\n" + 
"1Qi8B+dFcgRYKFrcpsVaZ1lBmXKsXDRu5QR/Rg3f9DRq4GR1sNH8RLY9uApMl2SN\n" + 
"z+sR4zRPG85R/se5Q06Gu0BUQ3UPm67ETVZLAgMBAAGjXzBdMAwGA1UdEwEB/wQC\n" + 
"MAAwCwYDVR0PBAQDAgbAMBYGA1UdJQEB/wQMMAoGCCsGAQUFBwMIMCgGA1UdHwQh\n" + 
"MB8wHaAboBmGF2h0dHA6Ly90ZXN0LmNvbS9jYTEuY3JsMA0GCSqGSIb3DQEBBQUA\n" + 
"A4IBAQBNkm5GniFi3PKqbafCVN8mpHWJjF2stCRTVxeTCIXUC63YD5XKABGzPH+Y\n" + 
"2R8fCrOa8cGlHmFXOlJye/lnXeZodPyxJUvAKohTp6sG+rJVId8ISI2Io2i5BF8a\n" + 
"CHdm8qd8E0fJvBudqkEc26Ia6tFSA/gEW0ffhsCkN/lXUAjuvDLqtTtU7zBU6dIl\n" + 
"h12Pwyf+x6AsYSciA9zWC6OE590K8Jr2z4u85biM7viWvPeZPNHSNM1fe+8wKbP8\n" + 
"64JtLj/VrglcsXALaUalyh2Hs7gPQzjyus1fyhEWPO3T6KMcBMXjb6anxL5q9YO5\n" + 
"qx1hJTY3L1hahBcMTALQyTEiFv1S\n" + 
"-----END CERTIFICATE-----\n";

// ======= TEST ===============================================================

// ----- TimeStampResp --------------

test("TimeStampResp/1 with token(by params)", function() {
var hExpect = "3082024130030201003082023806092a864886f70d010702a082022930820225020103310f300d060960864801650304020105003053060b2a864886f70d0109100104a0440442304002010106042a0304053011300906052b0e03021a05000404a1a2a3a4020103181332303133313233313233353935392e3132335a3004800201f40101ff020103318201b8308201b40201013020301b310b3009060355040613025553310c300a060355040a0c0343413102014d300d06096086480165030402010500a06b301a06092a864886f70d010903310d060b2a864886f70d0109100104301c06092a864886f70d010905310f170d3133313233313233353935395a302f06092a864886f70d0109043122042024e488bbec64ebd7696c0e1aeff2743c697950f50d82404a4fb620d29f430259300d06092a864886f70d01010b0500048201003c2ef00801d245023bd1e519c7188e1585675550822de111b25db4cf6f3a400caec35758a5ceb08fb4a689eeb1541001f0c3ed5e1c2390cb9165bcde64cc6ed9e53752bfb8833784920be7f3838959180a46a6ade9b5cd901c4d845c95182cbedd37df79afc3096dc276d2e0c4b0ea514807e40d6bdac2c8fc83869f550968ccc0405b9f4e455ddb5683cc06bdc125afee75c898d29d1069a644721f12a51689508a1b09695978b828ff9025e877fd4b31ecde81ca1647be347dc47e8f2c85dc7d34e051382fa8ca5e834f8de224418f469d1eb78a631fa04f910a3de86c7badc273e212dba2b60791b0aec251046521fe9c2bd2d84f717f520035baa9a4577e";
var params = {
  statusinfo: 'granted',
  version: 1,
  hashalgs: ["sha256"],
  econtent: {
    type: "tstinfo",
    content: {
      policy: '1.2.3.4.5',
      messageImprint: { alg: 'sha1', hash: 'a1a2a3a4' },
      serial: {'int': 3},
      genTime: {str: '20131231235959.123Z', millis: true},
      accuracy: { millis: 500 },
      ordering: true,
      nonce: {'int': 3},
    }
  },
  sinfos: [{
    version: 1,
    id: {type:'isssn', cert: sZ4_CERPEM},
    hashalg: "sha256",
    sattrs: {array: [{
      attr: "contentType",
      type: "data"
    },{
      attr: "signingTime",
      str: '131231235959Z'
    },{
      attr: "messageDigest",
      hex: 'ffff'
    }]},
    sigalg: "SHA256withRSA",
    signkey: sZ4_PRVP8PPEM
  }]
};
var o = new KJUR.asn1.tsp.TimeStampResp(params);
equal(o.getEncodedHex(), hExpect, "hex");
equal(ASN1HEX.dump(o.getEncodedHex()),ASN1HEX.dump(hExpect), "dump");
});

test("TimeStampResp/2 with token(by tst)", function() {
var hExpect = "3082024130030201003082023806092a864886f70d010702a082022930820225020103310f300d060960864801650304020105003053060b2a864886f70d0109100104a0440442304002010106042a0304053011300906052b0e03021a05000404a1a2a3a4020103181332303133313233313233353935392e3132335a3004800201f40101ff020103318201b8308201b40201013020301b310b3009060355040613025553310c300a060355040a0c0343413102014d300d06096086480165030402010500a06b301a06092a864886f70d010903310d060b2a864886f70d0109100104301c06092a864886f70d010905310f170d3133313233313233353935395a302f06092a864886f70d0109043122042024e488bbec64ebd7696c0e1aeff2743c697950f50d82404a4fb620d29f430259300d06092a864886f70d01010b0500048201003c2ef00801d245023bd1e519c7188e1585675550822de111b25db4cf6f3a400caec35758a5ceb08fb4a689eeb1541001f0c3ed5e1c2390cb9165bcde64cc6ed9e53752bfb8833784920be7f3838959180a46a6ade9b5cd901c4d845c95182cbedd37df79afc3096dc276d2e0c4b0ea514807e40d6bdac2c8fc83869f550968ccc0405b9f4e455ddb5683cc06bdc125afee75c898d29d1069a644721f12a51689508a1b09695978b828ff9025e877fd4b31ecde81ca1647be347dc47e8f2c85dc7d34e051382fa8ca5e834f8de224418f469d1eb78a631fa04f910a3de86c7badc273e212dba2b60791b0aec251046521fe9c2bd2d84f717f520035baa9a4577e";
var params = {
  version: 1,
  hashalgs: ["sha256"],
  econtent: {
    type: "tstinfo",
    content: {
      policy: '1.2.3.4.5',
      messageImprint: { alg: 'sha1', hash: 'a1a2a3a4' },
      serial: {'int': 3},
      genTime: {str: '20131231235959.123Z', millis: true},
      accuracy: { millis: 500 },
      ordering: true,
      nonce: {'int': 3},
    }
  },
  sinfos: [{
    version: 1,
    id: {type:'isssn', cert: sZ4_CERPEM},
    hashalg: "sha256",
    sattrs: {array: [{
      attr: "contentType",
      type: "data"
    },{
      attr: "signingTime",
      str: '131231235959Z'
    },{
      attr: "messageDigest",
      hex: 'ffff'
    }]},
    sigalg: "SHA256withRSA",
    signkey: sZ4_PRVP8PPEM
  }]
};
var dTST = (new KJUR.asn1.tsp.TimeStampToken(params)).getContentInfo();
var o = new KJUR.asn1.tsp.TimeStampResp({statusinfo: 'granted', tst: dTST});
equal(o.getEncodedHex(), hExpect, "hex");
equal(ASN1HEX.dump(o.getEncodedHex()),ASN1HEX.dump(hExpect), "dump");
});

test("TimeStampResp/3 without token", function() {
var _TimeStampResp = KJUR.asn1.tsp.TimeStampResp;
var hExpect, params, o;

hExpect = "30053003020102";
params = {statusinfo: "rejection"}
o = new _TimeStampResp(params);
equal(o.getEncodedHex(), hExpect, "hex rejection");
equal(
ASN1HEX.dump(o.getEncodedHex()),
ASN1HEX.dump(hExpect),
"dump rejection");

hExpect = "301c301a02010230110c0f756e737570706f7274656420616c6703020780";
params = {statusinfo: {status:"rejection", statusstr:["unsupported alg"], failinfo: 'badAlg'}};
o = new _TimeStampResp(params);
equal(o.getEncodedHex(), hExpect, "hex rejection/str/badAlg");
equal(
ASN1HEX.dump(o.getEncodedHex()),
ASN1HEX.dump(hExpect),
"dump rejection/str/badAlg");
});

// ----- TimeStampToken -----------------

test("TimeStampToken test", function() {
var _TimeStampToken = KJUR.asn1.tsp.TimeStampToken;
var hExpect = "3082057306092a864886f70d010702a082056430820560020103310f300d060960864801650304020105003075060b2a864886f70d0109100104a0660464306202010106042a0304053011300906052b0e03021a05000404a1a2a3a4020103181332303133313233313233353935392e3132335a3004800201f40101ff020103a020a41e301c310b3009060355040613025553310d300b06035504030c0454534131a082031530820311308201f9a00302010202014d300d06092a864886f70d0101050500301b310b3009060355040613025553310c300a060355040a0c03434131301e170d3133303530313233353935395a170d3233303530313233353935395a301c310b3009060355040613025553310d300b06035504030c045453413130820122300d06092a864886f70d01010105000382010f003082010a0282010100df74eaa8b47779e5260ed1d2f3da85de9e0c3fb59faadd998e3de56632e38c2183bf0afd7093653438ae29ba0e0e05224f865d3d66ce88c01f0dc0f394ec40d380c39c414601ffa40d088d49ed99b6a0bb6e721cf3e2921bfa8e19021569acb851cafaa2f0e4ca43b91f19fb394eec269f533fd1f4247f3331003a6338a3607f4bb2ea537abad8dd4eb3ca28551035d73afd3cbc11e4e7404c1496c4f62c05c27c42b14e7e519519630f3b52ed27e0b3c54bd053f2d508bc07e745720458285adca6c55a6759419972ac5c346ee5047f460ddff4346ae06475b0d1fc44b63db80a4c97648dcfeb11e3344f1bce51fec7b9434e86bb405443750f9baec44d564b0203010001a35f305d300c0603551d130101ff04023000300b0603551d0f0404030206c030160603551d250101ff040c300a06082b0601050507030830280603551d1f0421301f301da01ba0198617687474703a2f2f746573742e636f6d2f6361312e63726c300d06092a864886f70d010105050003820101004d926e469e2162dcf2aa6da7c254df26a475898c5dacb424535717930885d40badd80f95ca0011b33c7f98d91f1f0ab39af1c1a51e61573a52727bf9675de66874fcb1254bc02a8853a7ab06fab25521df08488d88a368b9045f1a087766f2a77c1347c9bc1b9daa411cdba21aead15203f8045b47df86c0a437f9575008eebc32eab53b54ef3054e9d225875d8fc327fec7a02c61272203dcd60ba384e7dd0af09af6cf8bbce5b88ceef896bcf7993cd1d234cd5f7bef3029b3fceb826d2e3fd5ae095cb1700b6946a5ca1d87b3b80f4338f2bacd5fca11163cedd3e8a31c04c5e36fa6a7c4be6af583b9ab1d612536372f585a84170c4c02d0c9312216fd52318201b8308201b40201013020301b310b3009060355040613025553310c300a060355040a0c0343413102014d300d06096086480165030402010500a06b301a06092a864886f70d010903310d060b2a864886f70d0109100104301c06092a864886f70d010905310f170d3133313233313233353935395a302f06092a864886f70d01090431220420ef6140e7f86753fb5a1f1df95048fa31a513e645519c0642241f3e57dccde949300d06092a864886f70d01010b050004820100c046ab62621a19ab6648c9662f1907026df25d680312e79fad114562c488f09a5d3f54e8ec888fbb94fa928fc03d548f58f6320a944c1f8762123b031744733a1f4a8969588b0e38a552fd8b038e97cf388ae1c5c96a3caee56d3ee3263d6a7f440b5ebd9e5e5c88a4d569e96fd0b5dc0919707948407ac95085bd3772514e2a2fb031543154d43c0210f2faaf16f67d7eb899267994552213b0bb5d18b21a24605b9fc29c699fe6e10e4eeb857cc04fda5dd186669f25bd31697473e8f005ad0f8e1d0cbe6d8713195ef1e8d3867ea498947be58ebf8400b183dcb4c196150c160f9ff5ba62b38337c3e80cf0c07bc25cac83560434aa3d5881de23190de73e";
//var hExpect = "030101";
var params = {
  version: 1,
  hashalgs: ["sha256"],
  econtent: {
    type: "tstinfo",
    content: {
      policy: '1.2.3.4.5',
      messageImprint: { alg: 'sha1', hash: 'a1a2a3a4' },
      serial: {'int': 3},
      genTime: {str: '20131231235959.123Z', millis: true},
      //genTime: {},
      accuracy: { millis: 500 },
      ordering: true,
      nonce: {'int': 3},
      tsa: {certsubject: sZ4_CERPEM}
      //tsa: {'str': '/C=US/O=TSP1'}
    }
  },
  certs: [sZ4_CERPEM],
  sinfos: [{
    version: 1,
    id: {type:'isssn', cert: sZ4_CERPEM},
    hashalg: "sha256",
    sattrs: {array: [{
      attr: "contentType",
      type: "data"
    },{
      attr: "signingTime",
      str: '131231235959Z'
    },{
      attr: "messageDigest",
      hex: 'ffff'
    }]},
    sigalg: "SHA256withRSA",
    signkey: sZ4_PRVP8PPEM
  }]
};
var o = new _TimeStampToken(params);
equal(
o.getContentInfoEncodedHex(),
hExpect,
"hex1");
equal(
ASN1HEX.dump(o.getContentInfoEncodedHex()),
ASN1HEX.dump(hExpect),
"dump1");
});

// ----- Accuracy -----------------------
test("Accuracy", function() {
  expect(2);

  var o = new KJUR.asn1.tsp.Accuracy({seconds: 7, millis: 7, micros: 7});
  equal(o.getEncodedHex(), "3009020107800107810107", "");

  var o2 = new KJUR.asn1.tsp.Accuracy({millis: 500});
  equal(o2.getEncodedHex(), "3004800201f4", "");
});

test("MessageImprint", function() {
  expect(1);
  var o = new KJUR.asn1.tsp.MessageImprint({alg: 'sha256', hash: 'a1a2a3a4a5a6a7a8'});
  equal(o.getEncodedHex(), "3019300d060960864801650304020105000408a1a2a3a4a5a6a7a8", "");
});

test("TSTInfo test", function() {
var hExpect = "306202010106042a0304053011300906052b0e03021a05000404a1a2a3a4020103181332303133313233313233353935392e3132335a3004800201f40101ff020103a020a41e301c310b3009060355040613025553310d300b060355040a0c0454535031";
var o = new KJUR.asn1.tsp.TSTInfo({
  policy: '1.2.3.4.5',
  messageImprint: { alg: 'sha1', hash: 'a1a2a3a4' },
  serial: {'int': 3},
  genTime: {str: '20131231235959.123Z', millis: true},
  //genTime: {},
  accuracy: { millis: 500 },
  ordering: true,
  nonce: {'int': 3},
  tsa: {'str': '/C=US/O=TSP1'}
});
equal(o.getEncodedHex(), hExpect, "hex");
equal(
ASN1HEX.dump(o.getEncodedHex()), 
ASN1HEX.dump(hExpect),
"dump");
});

// ----- PKIStatusInfo related class -------------

test("PKIStatusInfo test", function() {
var o = new KJUR.asn1.tsp.PKIStatusInfo({
  status: 'rejection',
  statusstr: ['aaa'],
  failinfo: 'badAlg'
});
equal(o.getEncodedHex(), "300e02010230050c0361616103020780", "rejection/str=[aaa]/badAlg");

var o2 = new KJUR.asn1.tsp.PKIStatusInfo("granted");
equal(o2.getEncodedHex(), "3003020100", "granted");
});

test("PKIStatus test", function() {
var o = new KJUR.asn1.tsp.PKIStatus(0);
equal(o.getEncodedHex(), "020100", "by int 0");

var o2 = new KJUR.asn1.tsp.PKIStatus('granted');
equal(o2.getEncodedHex(), "020100", "by name granted");
});

test("PKIFreeText test", function() {
var o = new KJUR.asn1.tsp.PKIFreeText(['aaa', 'bbb']);
equal(o.getEncodedHex(), "300a0c036161610c03626262", "by [aaa, bbb]");
});

test("PKIFailureInfo test", function() {
var o;
o = new KJUR.asn1.tsp.PKIFailureInfo(0);
equal(o.getEncodedHex(), "03020780", "0");
o = new KJUR.asn1.tsp.PKIFailureInfo(2);
equal(o.getEncodedHex(), "03020520", "2");
o = new KJUR.asn1.tsp.PKIFailureInfo(25);
equal(o.getEncodedHex(), "03050600000040", "25");
o = new KJUR.asn1.tsp.PKIFailureInfo('badAlg');
equal(o.getEncodedHex(), "03020780", "badAlg");
o = new KJUR.asn1.tsp.PKIFailureInfo('badRequest');
equal(o.getEncodedHex(), "03020520", "badRequest");
o = new KJUR.asn1.tsp.PKIFailureInfo('systemFailure');
equal(o.getEncodedHex(), "03050600000040", "systemFailure");
o = new KJUR.asn1.tsp.PKIFailureInfo(['badAlg','badRequest']);
equal(o.getEncodedHex(), "030205a0", "[badAlg,badRequest]");
o = new KJUR.asn1.tsp.PKIFailureInfo(['badAlg','badRequest','systemFailure']);
equal(o.getEncodedHex(), "030506a0000040", "[badAlg,badRequest,systemFailure]");
});

test("PKIFailureInfo.getBinValue test", function() {
var o;
o = new KJUR.asn1.tsp.PKIFailureInfo(0);
equal(o.getBinValue(), "1", "0");
o = new KJUR.asn1.tsp.PKIFailureInfo(2);
equal(o.getBinValue(), "001", "2");
o = new KJUR.asn1.tsp.PKIFailureInfo(25);
equal(o.getBinValue(), "00000000000000000000000001", "25");
o = new KJUR.asn1.tsp.PKIFailureInfo('timeNotAvailable');
equal(o.getBinValue(), "000000000000001", "timeNotAvailable");
o = new KJUR.asn1.tsp.PKIFailureInfo(['badAlg','systemFailure','badRequest']);
equal(o.getBinValue(), "10100000000000000000000001", "[badAlg,systemFailure,badRequest]");
});

test("TimeStampReq", function() {
var _TimeStampReq = KJUR.asn1.tsp.TimeStampReq;

var hExpect = "30260201013015300d060960864801650304020105000404a1a2a3a406042a03040502049abcf318";

var params = {
  messageImprint: new KJUR.asn1.tsp.MessageImprint({alg: 'sha256', hash: 'a1a2a3a4'}),
  policy: {oid: '1.2.3.4.5'},
  nonce: {hex: '9abcf318'},
  certreq: false
};
var o = new _TimeStampReq(params);
equal(o.getEncodedHex(), hExpect, "hex");
equal(
ASN1HEX.dump(o.getEncodedHex()),
ASN1HEX.dump(hExpect),
"dump");

var hExpect2 = "302b0201013015300d060960864801650304020105000404a1a2a3a406040101020202068a8b8c8d8e8f0101ff";
//var hExpect2 = "030101";
var params2 = {
  policy: {oid: '0.1.1.2.2'},
  messageImprint: {alg: 'sha256', hash: 'a1a2a3a4'},
  nonce: {hex: '8a8b8c8d8e8f'},
  certreq: true
}
var o2 = new _TimeStampReq(params2);
equal(o2.getEncodedHex(), hExpect2, "hex2");
equal(
ASN1HEX.dump(o2.getEncodedHex()),
ASN1HEX.dump(hExpect2),
"dump2");

});

// ----- newTimeStampToken -----------

test("TSPUtil.newTimeStampToken test (DEPRECATED)", function() {
var hExpect = "3082023806092a864886f70d010702a082022930820225020103310f300d060960864801650304020105003053060b2a864886f70d0109100104a0440442304002010106042a0304053011300906052b0e03021a05000404a1a2a3a4020103181332303133313233313233353935392e3132335a3004800201f40101ff020103318201b8308201b40201013020301b310b3009060355040613025553310c300a060355040a0c0343413102014d300d06096086480165030402010500a06b301a06092a864886f70d010903310d060b2a864886f70d0109100104301c06092a864886f70d010905310f170d3133313233313233353935395a302f06092a864886f70d0109043122042024e488bbec64ebd7696c0e1aeff2743c697950f50d82404a4fb620d29f430259300d06092a864886f70d01010b0500048201003c2ef00801d245023bd1e519c7188e1585675550822de111b25db4cf6f3a400caec35758a5ceb08fb4a689eeb1541001f0c3ed5e1c2390cb9165bcde64cc6ed9e53752bfb8833784920be7f3838959180a46a6ade9b5cd901c4d845c95182cbedd37df79afc3096dc276d2e0c4b0ea514807e40d6bdac2c8fc83869f550968ccc0405b9f4e455ddb5683cc06bdc125afee75c898d29d1069a644721f12a51689508a1b09695978b828ff9025e877fd4b31ecde81ca1647be347dc47e8f2c85dc7d34e051382fa8ca5e834f8de224418f469d1eb78a631fa04f910a3de86c7badc273e212dba2b60791b0aec251046521fe9c2bd2d84f717f520035baa9a4577e";
var params = {
  version: 1,
  hashalgs: ["sha256"],
  econtent: {
    type: "tstinfo",
    content: {
      policy: '1.2.3.4.5',
      messageImprint: { alg: 'sha1', hash: 'a1a2a3a4' },
      serial: {'int': 3},
      genTime: {str: '20131231235959.123Z', millis: true},
      accuracy: { millis: 500 },
      ordering: true,
      nonce: {'int': 3},
    }
  },
  sinfos: [{
    version: 1,
    id: {type:'isssn', cert: sZ4_CERPEM},
    hashalg: "sha256",
    sattrs: {array: [{
      attr: "contentType",
      type: "data"
    },{
      attr: "signingTime",
      str: '131231235959Z'
    },{
      attr: "messageDigest",
      hex: 'ffff'
    }]},
    sigalg: "SHA256withRSA",
    signkey: sZ4_PRVP8PPEM
  }]
};
var o = KJUR.asn1.tsp.TSPUtil.newTimeStampToken(params);
equal(o.getContentInfoEncodedHex(), hExpect, "hex");
equal(
ASN1HEX.dump(o.getContentInfoEncodedHex()),
ASN1HEX.dump(hExpect),
"dump");

});

// ----- TSPUtil.parseTimeStampReq ------

test("TSPUtil.parseTimeStampReq (DEPRECATED)", function() {
var _parseTimeStampReq = KJUR.asn1.tsp.TSPUtil.parseTimeStampReq;
var hIn, pExpect;

hIn = "30260201013015300d060960864801650304020105000404a1a2a3a406042a03040502049abcf318";
pExpect = {
  policy: "1.2.3.4.5",
  messageImprint: {
    alg: "sha256",
    hash: "a1a2a3a4"
  },
  nonce: "9abcf318",
  certreq: false
}
deepEqual(_parseTimeStampReq(hIn), pExpect, "p1");

hIn = "302b0201013015300d060960864801650304020105000404a1a2a3a406040101020202068a8b8c8d8e8f0101ff";
pExpect = {
  policy: "0.1.1.2.2",
  messageImprint: {
    alg: "sha256",
    hash: "a1a2a3a4"
  },
  nonce: "8a8b8c8d8e8f",
  certreq: true
}
deepEqual(_parseTimeStampReq(hIn), pExpect, "p1");

hIn = "304c0201013031300d0609608648016503040201050004209834876dcfb05cb167a5c24953eba58c4ac89b1adf57f28f2f9d09af107ee8f006042a030405020b1a1b1c1e1f2a2b2c2d2e2f0101ff";
var pExpect = {
  policy: "1.2.3.4.5",
  messageImprint: {
    alg: "sha256",
    hash: "9834876dcfb05cb167a5c24953eba58c4ac89b1adf57f28f2f9d09af107ee8f0"
  },
  nonce: "1a1b1c1e1f2a2b2c2d2e2f",
  certreq: true
}
deepEqual(_parseTimeStampReq(hIn), pExpect, "p1");
});

test("TSPUtil.parseMessageImprint (DEPRECATED)", function() {
var _parse = KJUR.asn1.tsp.TSPUtil.parseMessageImprint;
var hIn, pExpect;

hIn = "3031300d06096086480165030402010500042017e682f060b5f8e47ea04c5c4855908b0a5ad612022260fe50e11ecb0cc0ab76";
pExpect = {
  alg: "sha256",
  hash: "17e682f060b5f8e47ea04c5c4855908b0a5ad612022260fe50e11ecb0cc0ab76"
};
deepEqual(_parse(hIn), pExpect, "sha256 aaa");
});

test("FixedTSAAdapter test", function() {
var tstaaa = "3082025806092a864886f70d010702a082024930820245020103310f300d060960864801650304020105003073060b2a864886f70d0109100104a0640462306002010106042a0304053031300d0609608648016503040201050004209834876dcfb05cb167a5c24953eba58c4ac89b1adf57f28f2f9d09af107ee8f0020103181332303133313233313233353935392e3132335a3004800201f40101ff020103318201b8308201b40201013020301b310b3009060355040613025553310c300a060355040a0c0343413102014d300d06096086480165030402010500a06b301a06092a864886f70d010903310d060b2a864886f70d0109100104301c06092a864886f70d010905310f170d3133313233313233353935395a302f06092a864886f70d01090431220420b881ee6a3cea0846b14be1087b4481a6f84f0f44b6cc7134b0a5def375ba2211300d06092a864886f70d01010b050004820100beeb77762b57dd6a093a0fbecdf1bf9f374ec6d4fbff87cc912628f6e28cae734a8255176f356082494586faed2064a009878e31b69abb9854a3fb9b5efa89c28a711fee3d14a9b85e3edcacb36687878cb19e5ac710fd99132b59b529975b35660579edd7237d338d3184fdd194fc778f794a6f7b9659c3c3d4441b9f26cc31a72cf528ec3cee73b7c8ea049b8b598c21ac6045bbe1641c3d00d302426ab7eff7d94f6d93821e6ab9a6a6610e78222bb9097f49179b550542aa51f79faf3dd8303aa9871d93bc796c7ca7f621389a784658f75dbeeafd0c35e7f25bbd8c9db67424be4486f4341d38241111f4f5d0fc8592c1e537f796eb1cb534648d6efe10";

var tstbbb = "3082027c06092a864886f70d010702a082026d30820269020103310f300d06096086480165030402010500308196060b2a864886f70d0109100104a0818604818330818002010106042a0304053051300d0609608648016503040203050004405edc1c6a4390075a3ca27f4d4161c46b374b1c3b2d63f846db6fff0c513203c3ac3b14a24a6f09d8bf21407a4842113b5d9aa359d266299c3d6cf9e92db66dbe020103181332303133313233313233353935392e3132335a3004800201f40101ff020103318201b8308201b40201013020301b310b3009060355040613025553310c300a060355040a0c0343413102014d300d06096086480165030402010500a06b301a06092a864886f70d010903310d060b2a864886f70d0109100104301c06092a864886f70d010905310f170d3133313233313233353935395a302f06092a864886f70d0109043122042008a40e26152ed70e1d136154cb689a24a68c1c508a8369e7c6a1f702ccd15158300d06092a864886f70d01010b050004820100beeb77762b57dd6a093a0fbecdf1bf9f374ec6d4fbff87cc912628f6e28cae734a8255176f356082494586faed2064a009878e31b69abb9854a3fb9b5efa89c28a711fee3d14a9b85e3edcacb36687878cb19e5ac710fd99132b59b529975b35660579edd7237d338d3184fdd194fc778f794a6f7b9659c3c3d4441b9f26cc31a72cf528ec3cee73b7c8ea049b8b598c21ac6045bbe1641c3d00d302426ab7eff7d94f6d93821e6ab9a6a6610e78222bb9097f49179b550542aa51f79faf3dd8303aa9871d93bc796c7ca7f621389a784658f75dbeeafd0c35e7f25bbd8c9db67424be4486f4341d38241111f4f5d0fc8592c1e537f796eb1cb534648d6efe10";

var params = {
  statusinfo: 'granted',
  version: 1,
  hashalgs: ["sha256"],
  econtent: {
    type: "tstinfo",
    content: {
      policy: '1.2.3.4.5',
      messageImprint: { alg: 'sha1', hash: 'a1a2a3a4' },
      serial: {'int': 3},
      genTime: {str: '20131231235959.123Z', millis: true},
      accuracy: { millis: 500 },
      ordering: true,
      nonce: {'int': 3},
    }
  },
  sinfos: [{
    version: 1,
    id: {type:'isssn', cert: sZ4_CERPEM},
    hashalg: "sha256",
    sattrs: {array: [{
      attr: "contentType",
      type: "data"
    },{
      attr: "signingTime",
      str: '131231235959Z'
    },{
      attr: "messageDigest",
      hex: 'ffff'
    }]},
    sigalg: "SHA256withRSA",
    signkey: sZ4_PRVP8PPEM
  }]
};

var tsa = new KJUR.asn1.tsp.FixedTSAAdapter(params);

equal(
ASN1HEX.dump(tsa.getTSTHex('616161', 'sha256')),
ASN1HEX.dump(tstaaa),
"aaa 1 dump");

equal(
ASN1HEX.dump(tsa.getTSTHex('626262', 'sha512')),
ASN1HEX.dump(tstbbb),
"bbb 1 sha512 dump");

equal(tsa.getTSTHex('616161', 'sha256'), tstaaa, 'aaa 1');
equal(tsa.getTSTHex('616161', 'sha256'), tstaaa, 'aaa 2');
equal(tsa.getTSTHex('626262', 'sha512'), tstbbb, 'bbb 1');
equal(tsa.getTSTHex('626262', 'sha512'), tstbbb, 'bbb 2');
});

test("SimpleTSAAdapter", function() {
var params = {
  statusinfo: 'granted',
  version: 1,
  hashalgs: ["sha256"],
  econtent: {
    type: "tstinfo",
    content: {
      policy: '1.2.3.4.5',
      messageImprint: { alg: 'sha1', hash: 'a1a2a3a4' },
      serial: {'int': 3},
      genTime: {str: '20131231235959.123Z', millis: true},
      accuracy: { millis: 500 },
      ordering: true,
      nonce: {'int': 3},
    }
  },
  sinfos: [{
    version: 1,
    id: {type:'isssn', cert: sZ4_CERPEM},
    hashalg: "sha256",
    sattrs: {array: [{
      attr: "contentType",
      type: "data"
    },{
      attr: "signingTime",
      str: '131231235959Z'
    },{
      attr: "messageDigest",
      hex: 'ffff'
    }]},
    sigalg: "SHA256withRSA",
    signkey: sZ4_PRVP8PPEM
  }]
};

var tsa = new KJUR.asn1.tsp.SimpleTSAAdapter(params);

equal(tsa.getTSTHex('616161', 'sha256').substr(0, 2), '30', 'aaa 1');
equal(tsa.getTSTHex('616161', 'sha256').substr(0, 2), '30', 'aaa 2');
equal(tsa.getTSTHex('626262', 'sha256').substr(0, 2), '30', 'bbb 1');
equal(tsa.getTSTHex('626262', 'sha256').substr(0, 2), '30', 'bbb 2');
});

test("TSPParser test", function() {
var hTSR = "3082024130030201003082023806092a864886f70d010702a082022930820225020103310f300d060960864801650304020105003053060b2a864886f70d0109100104a0440442304002010106042a0304053011300906052b0e03021a05000404a1a2a3a4020103181332303133313233313233353935392e3132335a3004800201f40101ff020103318201b8308201b40201013020301b310b3009060355040613025553310c300a060355040a0c0343413102014d300d06096086480165030402010500a06b301a06092a864886f70d010903310d060b2a864886f70d0109100104301c06092a864886f70d010905310f170d3133313233313233353935395a302f06092a864886f70d0109043122042024e488bbec64ebd7696c0e1aeff2743c697950f50d82404a4fb620d29f430259300d06092a864886f70d01010b0500048201003c2ef00801d245023bd1e519c7188e1585675550822de111b25db4cf6f3a400caec35758a5ceb08fb4a689eeb1541001f0c3ed5e1c2390cb9165bcde64cc6ed9e53752bfb8833784920be7f3838959180a46a6ade9b5cd901c4d845c95182cbedd37df79afc3096dc276d2e0c4b0ea514807e40d6bdac2c8fc83869f550968ccc0405b9f4e455ddb5683cc06bdc125afee75c898d29d1069a644721f12a51689508a1b09695978b828ff9025e877fd4b31ecde81ca1647be347dc47e8f2c85dc7d34e051382fa8ca5e834f8de224418f469d1eb78a631fa04f910a3de86c7badc273e212dba2b60791b0aec251046521fe9c2bd2d84f717f520035baa9a4577e";

var parser = new KJUR.asn1.tsp.TSPParser();

var pExpect1 = {
  statusinfo: {status: "granted"},
  version: 3,
  hashalgs: ["sha256"],
  econtent: {
    type: "tstinfo",
    content: {
      policy: "1.2.3.4.5",
      messageImprint: {
        "alg": "sha1",
        "hash": "a1a2a3a4"
      },
      genTime: {str: "20131231235959.123Z"},
      serial: {hex: "03"},
      accuracy: {millis: 500},
      ordering: true,
      nonce: {hex: "03"}
    }
  },
  sinfos: [{
    version: 1,
    hashalg: "sha256",
    id: {
      type: "isssn",
      issuer: {
        array: [
          [{type:"C",value:"US",ds:"prn"}],
          [{type:"O",value:"CA1",ds:"utf8"}]
        ],
        str: "/C=US/O=CA1"
      },
      serial: {hex: "4d"}
    },
    sattrs: {
      array: [{
        attr: "contentType",
        type: "tstinfo"
      },{
        attr: "signingTime",
        str: "131231235959Z"
      },{
        attr: "messageDigest",
        hex: "24e488bbec64ebd7696c0e1aeff2743c697950f50d82404a4fb620d29f430259"
      }]
    },
    sigalg: "SHA256withRSA",
    sighex: "3c2ef00801d245023bd1e519c7188e1585675550822de111b25db4cf6f3a400caec35758a5ceb08fb4a689eeb1541001f0c3ed5e1c2390cb9165bcde64cc6ed9e53752bfb8833784920be7f3838959180a46a6ade9b5cd901c4d845c95182cbedd37df79afc3096dc276d2e0c4b0ea514807e40d6bdac2c8fc83869f550968ccc0405b9f4e455ddb5683cc06bdc125afee75c898d29d1069a644721f12a51689508a1b09695978b828ff9025e877fd4b31ecde81ca1647be347dc47e8f2c85dc7d34e051382fa8ca5e834f8de224418f469d1eb78a631fa04f910a3de86c7badc273e212dba2b60791b0aec251046521fe9c2bd2d84f717f520035baa9a4577e"
  }],
};
deepEqual(parser.getResponse(hTSR), pExpect1, "TimeStampResp");

var hIn2 = "3009020107800107810107";
var pExpect2 = {seconds: 7, millis: 7, micros: 7};
deepEqual(parser.getAccuracy(hIn2), pExpect2, "accuracy=7,7,7");

var hIn3 = "3004800201f4";
var pExpect3 = {millis: 500};
deepEqual(parser.getAccuracy(hIn3), pExpect3, "accuracy=-,500,-");

var hIn4 = "306202010106042a0304053011300906052b0e03021a05000404a1a2a3a4020103181332303133313233313233353935392e3132335a3004800201f40101ff020103a020a41e301c310b3009060355040613025553310d300b060355040a0c0454535031";
var pExpect4 = {
  policy: "1.2.3.4.5",
  messageImprint: {alg: "sha1", hash: "a1a2a3a4"},
  serial: {hex: "03"},
  genTime: {str: "20131231235959.123Z"},
  accuracy: {millis: 500},
  ordering: true,
  nonce: {hex: "03"},
  tsa: {
    array: [
      [{type:"C",value:"US",ds:"prn"}],
      [{type:"O",value:"TSP1",ds:"utf8"}]
    ],
    str: "/C=US/O=TSP1"
  }
};
deepEqual(parser.getTSTInfo(hIn4), pExpect4, "tstinfo");

});

test("TSPParser.getPKIStatusInfo test", function() {
var parser = new KJUR.asn1.tsp.TSPParser();

deepEqual(parser.getPKIStatusInfo("3003020100"), {status: "granted"}, "granted");

deepEqual(
parser.getPKIStatusInfo("3028020100300f0c036161610c036161610c03616161"),
{status: "granted", statusstr: ["aaa", "aaa", "aaa"]},
"granted [aaa,aaa,aaa]");

deepEqual(
parser.getPKIStatusInfo("300702010203020700"),
{status: "rejection", failinfo: "badAlg"},
"reject badAlg");

});

test("TSPParser.getPKIFreeText test", function() {
var parser = new KJUR.asn1.tsp.TSPParser();
var hIn = "300f0c036161610c036161610c03616161";
var aExp = ["aaa", "aaa", "aaa"];
deepEqual(parser.getPKIFreeText(hIn), aExp, "[aaa,aaa,aaa]");
});

test("TSPParser.getPKIFailureInfo test", function() {
var parser = new KJUR.asn1.tsp.TSPParser();
equal(parser.getPKIFailureInfo("030203c8"), "systemFailure", "03c8=systemFailure");
equal(parser.getPKIFailureInfo("03020700"), "badAlg", "0700=badAlg");
equal(parser.getPKIFailureInfo("03020780"), 1, "0780=1");
});

test("TSPParser.getMessageImprint test", function() {
var _parser = new KJUR.asn1.tsp.TSPParser();
var _getMessageImprint = _parser.getMessageImprint;
var hIn, pExpect;
hIn = "3031300d06096086480165030402010500042017e682f060b5f8e47ea04c5c4855908b0a5ad612022260fe50e11ecb0cc0ab76";
pExpect = {
    alg: "sha256",
    hash: "17e682f060b5f8e47ea04c5c4855908b0a5ad612022260fe50e11ecb0cc0ab76"
};
deepEqual(_getMessageImprint(hIn), pExpect, "sha256 aaa");
});

test("TSPParser.getTimeStampReq test", function() {
var _parser = new KJUR.asn1.tsp.TSPParser();
var _getTimeStampReq = _parser.getTimeStampReq;
var hIn, pExpect;
hIn = "30390201013031300d06096086480165030402010500042017e682f060b5f8e47ea04c5c4855908b0a5ad612022260fe50e11ecb0cc0ab760101ff";
pExpect = {
    messageImprint: {
	alg: "sha256",
	hash: "17e682f060b5f8e47ea04c5c4855908b0a5ad612022260fe50e11ecb0cc0ab76"
    },
    certreq: true
};
deepEqual(_getTimeStampReq(hIn), pExpect, "sha256 aaa certreq=true");
});

});

-->
</script>
  
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture">test markup</div>

<p>
<a href="../">TOP</a> | 
<a href="index.html">TEST INDEX</a> | 
<a href="qunit-do-asn1.html">asn1</a> | 
<a href="qunit-do-asn1x509.html">asn1x509</a> | 
<a href="qunit-do-asn1cms.html">asn1cms</a> | 
<a href="qunit-do-asn1tsp.html">asn1tsp</a> | 
<a href="../api/index.html">APIDOCS</a> | 
</p>

</body>
</html>
